A Constant Optimization of the Binary Indexed Tree Query Operation

نویسنده

  • Anubhav Baweja
چکیده

There are several data structures which can calculate the prefix sums of an array efficiently, while handling point updates on the array, such as Segment Trees and Binary Indexed Trees (BIT). Both these data structures can handle the these two operations (query and update) in O(log n) time. In this paper, we present a data structure similar to the BIT, but with an even smaller constant. To do this, we use Zeckendorf’s Theorem, a property of the Fibonacci sequence of numbers. The new data structure achieves the same complexity of O(log n), but requires about logφ2 n computations for the Query Operation as opposed to the log2 n computations required for a BIT Query Operation in the worst case. 1 Problem Motivation A Prefix Sum is defined as the sum of the first n elements of an array, where 1 ≤ n ≤ size(array). The problem can be traditionally solved on an array arr by creating a prefix sum array pre such that pre[1] = arr[1] (1) pre[i] = pre[i− 1] + arr[i] (2) (The above equations follow 1-based indexing) The Query Operation is defined as calculating the Prefix Sum of any index. The Update Operation is defined as assigning a new value to any index in the arr array. It is easy to see that the above pre array can handle the Query Operation in O(1) time, since it only requires a single memory call. However, the Update Operation is highly inefficient without the use of any data structure, taking O(n) time in the worst case (when updating the last element in the array). The Segment Tree and the Binary Indexed Tree (BIT) [1] are two structures which can handle both the Query and the Update Operation in O(log n) time. However, a BIT is much more efficient than a Segment Tree due to a smaller constant. In this paper, we present an alternative to the BIT, which we will call the Fibonacci Indexed Tree (FIT), for the sake of convenience. It can be shown that in the worst case, FIT takes about logφ2 n computations for the Query Operation and about logφ n) computations for the Update Operation. The problem of handling the above two operations simultaneously on a collection of data is an important one. It is used to solve several problems such as the Line-of-Sight Problem and is used in the implementation of multiple algorithms such as Radix Sort, lexical comparison of strings and Arithmetic Coding for data compression [2] [3]. When extended to two dimensions, Prefix Sums (the sum of all elements in a prefix rectangle) can be used in image processing and geographical information systems [4]. 1 ar X iv :1 61 2. 09 08 3v 1 [ cs .D S] 2 9 D ec 2 01 6 2 Preliminaries Before introducing the data structure, we will first tackle the few definitions and concepts which are required to understand its mechanism. We will be discussing the following topics: • Zeckendorf’s Theorem [5] • Fibonacci Coding • Least Significant Used Fibonacci • Mechanism of the Binary Indexed Tree 2.1 Zeckendorf’s Theorem This theorem states that every positive integer can be expressed as the sum of distinct nonconsecutive terms of the Fibonacci Sequence of numbers. Example: 46 can expressed as 46 = 34 + 8 + 3 + 1. This is called the Zeckendorf Representation of the number. The theorem also states that there exists only one Zeckendorf Representation of every positive integer. The Zeckendorf Representation of a number can be obtained by using a Greedy Algorithm. At every step, simply take the largest Fibonacci number smaller than the required number and subtract it. Now, repeat the step until a Fibonacci number is obtained. All the Fibonacci Numbers that were subtracted and the number finally obtained together make up the Zeckendorf Representation. 2.2 Fibonacci Coding An alternate way to write the Zeckendorf Representation of a number is ’Fibonacci Coding’. For a number N , we define the Fibonacci Coding of the number as follows:

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Efficient Range Minimum Queries using Binary Indexed Trees

We present new results on Binary Indexed Trees in order to efficiently solve Range Minimum Queries. We introduce a way of using the Binary Indexed Trees so that we can answer different types of queries, e.g. the range minimum query, in O (log N ) time complexity per operation, outperforming in speed similar data structures like Segment/Range Trees or the Sparse Table Algorithm.

متن کامل

A Comparison of Indexed Temporal Joins

We examine temporal joins in the presence of indexing schemes. Utilizing an index when processing join queries is especially advantageous if the join predicates involve only a portion of the temporal relations. This is a novel problem since temporal indices have various characteristics that can affect join processing drastically. For example, temporal indices commonly introduce record copies to...

متن کامل

Enhancing Rollover Threshold of an Elliptical Container Based on Binary-coded Genetic Algorithm

In this paper, a method based on binary-coded genetic algorithm is proposed to explore an optimization method, for obtaining an optimal elliptical tank. This optimization method enhances the rollover threshold of a tank vehicle, especially under partial filling conditions. Minimizing the overturning moment imposed on the vehicle due to c.g. height of the liquid load, lateral acceleration and ca...

متن کامل

A New Data Structure for Cumulative Frequency Tables

A new method (the ‘binary indexed tree’) is presented for maintaining the cumulative frequencies which are needed to support dynamic arithmetic data compression. It is based on a decomposition of the cumulative frequencies into portions which parallel the binary representation of the index of the table element (or symbol). The operations to traverse the data structure are based on the binary co...

متن کامل

An improved algorithm to reconstruct a binary tree from its inorder and postorder traversals

It is well-known that, given inorder traversal along with one of the preorder or postorder traversals of a binary tree, the tree can be determined uniquely. Several algorithms have been proposed to reconstruct a binary tree from its inorder and preorder traversals. There is one study to reconstruct a binary tree from its inorder and postorder traversals, and this algorithm takes running time of...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:
  • CoRR

دوره abs/1612.09083  شماره 

صفحات  -

تاریخ انتشار 2016